package com.frxuexi.park2303

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.findNavController
import androidx.navigation.ui.NavigationUI
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.base.mvi.BaseViewActivity
import com.frxuexi.base.utils.LiveDataBus
import com.frxuexi.park2303.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

@Route(path = "/app/MainActivity")
@AndroidEntryPoint
class MainActivity : BaseViewActivity<ActivityMainBinding>() {
    override fun getBind(): ActivityMainBinding {
        return ActivityMainBinding.inflate(layoutInflater)
    }

    override fun initView() {
        val navController = findNavController(R.id.fragment_main)
        NavigationUI.setupWithNavController(binding.nav,navController)

        binding.nav.getOrCreateBadge(R.id.myFragment).apply {
            number=5
            badgeTextColor=Color.WHITE
            backgroundColor=Color.RED
        }

        binding.nav.menu.findItem(R.id.myFragment).setOnMenuItemClickListener {
            binding.nav.removeBadge(R.id.myFragment)
            false
        }

        EventBus.getDefault().register(this)


        LiveDataBus.with<String>("key").observe(this){
            ToastUtils.showLong(it)
            binding.nav.selectedItemId=R.id.cartFragment
        }

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun getMsg(msg:String){
        ToastUtils.showLong(msg)

    }

}